import VueRouter from 'vue-router'

//导入对应的路由组件
import HomeContainer from './components/tabbar/HomeContainer.vue'
import VipContainer from './components/tabbar/VipContainer.vue'
import ShopcarContainer from './components/tabbar/ShopcarContainer.vue'
import SearchContainer from './components/tabbar/SearchContainer.vue'

import NewsList from './components/news/NewsList.vue'
import NewsInfo from './components/news/NewsInfo.vue'

import PhotoList from './components/photos/PhotoList.vue'
import PhotoInfo from './components/photos/PhotoInfo.vue'
import GoodsList from './components/goods/GoodsList.vue'
import GoodsInfo from './components/goods/GoodsInfo.vue'
import GoodsDesc from './components/goods/GoodsDesc.vue'
import GoodsComment from './components/goods/GoodsComment.vue'

//3.创建路由对象
var router = new VueRouter({
    routes:[
        { path: '/', redirect: '/home' },
        { path: '/home', component: HomeContainer, meta:{ title: '首页' } },
        { path: '/vip', component: VipContainer, meta:{ title: '会员' } },
        { path: '/shopcar', component: ShopcarContainer, meta:{ title: '购物车' } },
        { path: '/search', component: SearchContainer, meta:{ title: '搜搜' } },

        { path: '/home/newslist', component: NewsList },
        { path: '/home/newsinfo/:id', component: NewsInfo },
        { path: '/home/photolist', component: PhotoList },
        { path: '/home/photoinfo/:id', component: PhotoInfo },
        { path: '/home/goodslist', component: GoodsList },
        { path: '/home/goodsinfo/:id', component: GoodsInfo, name: 'goodslist' },
        { path: '/home/goodsdesc/:id', component: GoodsDesc, name: 'goodsdesc' },
        { path: '/home/goodscomment/:id', component: GoodsComment, name: 'goodscomment' },

    ],
    linkActiveClass: 'mui-active' //覆盖默认的路由高亮的类，默认的类叫router-link-active
});

// 前置守卫
router.beforeEach((to, from, next) => {  //添加页面标题
    document.title = to.matched[0].meta.title;
    next()
});

// 后置钩子
router.afterEach((to, from) => {
    console.log('切换完成')
});

//把整个router对象暴露出去
export default router;